/*
#include "SequenceSolver.hpp"

SequenceSolver* solver = nullptr;

extern "C" __declspec(dllexport)
void _cdecl init_sequence_solver_(int* _sol_type, int* _pc_type, int* _first_step)
{
    assert(solver == nullptr);
    solver = new SequenceSolver(*_sol_type, *_pc_type, *_first_step);
}

extern "C" __declspec(dllexport)
void _cdecl apply_solver_(int* _step_id, int* _nrows, double* _A, double* _rhs)
{
    assert(solver);
    TEST_TIME record;
    solver->solve(*_step_id, *_nrows, _A, _rhs, record);
}

extern "C" __declspec(dllexport)
void _cdecl finish_sequence_solver_()
{
    assert(solver);
    delete solver; solver = nullptr;
}
*/

#include "FracSolver.hpp"
FracSolver* solver = nullptr;

extern "C" 
{
void apply_(const int* _matrixSize, const int * _matrixCapacity,
    const double* _as, const double* _a13, const double* _a23, const double* _a31, 
    const double* _a32, const double* _a33, const double* _b1, const double* _b2, const double* _x3,
    double* _x1_2, double* _b3);
// void zygemv()
}
// // __declspec(dllexport)
// void 
// // _cdecl 
// printc_(int* _nrows)
// {
//     printf("C lib: %d\n", *_nrows);
// }

// __declspec(dllexport)
void apply_(const int* _matrixSize, const int * _matrixCapacity,
    const double* _as, const double* _a13, const double* _a23, const double* _a31, 
    const double* _a32, const double* _a33, const double* _b1, const double* _b2, const double* _x3,
    double* _x1_2, double* _b3)
{
    if (solver == nullptr) solver = new FracSolver(1033, 0, 128);
    // if (*_matrixSize > 200 && solver->solver_type == 33) {
    //     printf("Migrate the solver to GPU\n");
    //     FracSolver* new_solver = new FracSolver(1033, 0, solver->capacity);
    //     deep_copy(solver, new_solver);
    //     // printf("apply 000\n");
    //     delete solver; solver = new_solver;
    //     // printf("apply 111\n");
    //     if (solver->solver_type == 1000) {
    //         CUBLAS_CHECK(cublasSetMatrix((*_matrixSize) << 1, (*_matrixSize) << 1, sizeof(double),
    //             _as, (*_matrixSize) << 1, solver->d_As, solver->capacity << 1 ));
    //     }
    //     // printf("End setup GPU\n");
    // }
    solver->solve(*_matrixSize, *_matrixCapacity, _as, _a13, _a23, _a31, _a32, _a33, _b1, _b2, _x3, _x1_2, _b3);
}
